
CREATE DATABASE [Storage]

USE [Storage]
GO
/****** Object:  Table [dbo].[Category]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Category](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CName] [nvarchar](20) NOT NULL,
 CONSTRAINT [PK_Sort] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Customer]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Customer](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CName] [nvarchar](20) NOT NULL,
	[Address] [nvarchar](50) NOT NULL,
	[Phone] [nvarchar](20) NOT NULL,
 CONSTRAINT [PK_Client] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Depot]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Depot](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[DName] [nvarchar](20) NOT NULL,
	[Phone] [nvarchar](20) NOT NULL,
 CONSTRAINT [PK_Depot] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Goods]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Goods](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GoodsId] [nvarchar](10) NOT NULL,
	[GName] [nvarchar](20) NOT NULL,
	[UnitePrice] [decimal](8, 2) NOT NULL,
	[Manufacture] [nvarchar](20) NOT NULL,
	[Category] [nvarchar](20) NOT NULL,
 CONSTRAINT [PK_Goods] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[InStock]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InStock](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GoodsId] [int] NOT NULL,
	[DepotId] [int] NOT NULL,
	[ProviderId] [int] NOT NULL,
	[InNum] [int] NOT NULL,
	[InDate] [datetime] NOT NULL,
 CONSTRAINT [PK_InStock] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[OutStock]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OutStock](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GoodsId] [int] NOT NULL,
	[DepotId] [int] NOT NULL,
	[CustomerId] [int] NOT NULL,
	[OutNum] [int] NOT NULL,
	[OutDate] [datetime] NOT NULL,
 CONSTRAINT [PK_OutStock] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Provider]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Provider](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PName] [nvarchar](20) NOT NULL,
	[Phone] [nvarchar](20) NOT NULL,
	[Address] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Supplier] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[StorageInfo]    Script Date: 2020/8/14 19:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StorageInfo](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GoodsId] [int] NOT NULL,
	[DepotId] [int] NOT NULL,
	[StorageNum] [int] NOT NULL,
 CONSTRAINT [PK_StorageInfo] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InStock]  WITH CHECK ADD  CONSTRAINT [FK_InStock_Depot] FOREIGN KEY([DepotId])
REFERENCES [dbo].[Depot] ([Id])
GO
ALTER TABLE [dbo].[InStock] CHECK CONSTRAINT [FK_InStock_Depot]
GO
ALTER TABLE [dbo].[InStock]  WITH CHECK ADD  CONSTRAINT [FK_InStock_Goods] FOREIGN KEY([GoodsId])
REFERENCES [dbo].[Goods] ([Id])
GO
ALTER TABLE [dbo].[InStock] CHECK CONSTRAINT [FK_InStock_Goods]
GO
ALTER TABLE [dbo].[InStock]  WITH CHECK ADD  CONSTRAINT [FK_InStock_Provider] FOREIGN KEY([ProviderId])
REFERENCES [dbo].[Provider] ([Id])
GO
ALTER TABLE [dbo].[InStock] CHECK CONSTRAINT [FK_InStock_Provider]
GO
ALTER TABLE [dbo].[OutStock]  WITH CHECK ADD  CONSTRAINT [FK_OutStock_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([Id])
GO
ALTER TABLE [dbo].[OutStock] CHECK CONSTRAINT [FK_OutStock_Customer]
GO
ALTER TABLE [dbo].[OutStock]  WITH CHECK ADD  CONSTRAINT [FK_OutStock_Depot] FOREIGN KEY([DepotId])
REFERENCES [dbo].[Depot] ([Id])
GO
ALTER TABLE [dbo].[OutStock] CHECK CONSTRAINT [FK_OutStock_Depot]
GO
ALTER TABLE [dbo].[OutStock]  WITH CHECK ADD  CONSTRAINT [FK_OutStock_Goods] FOREIGN KEY([GoodsId])
REFERENCES [dbo].[Goods] ([Id])
GO
ALTER TABLE [dbo].[OutStock] CHECK CONSTRAINT [FK_OutStock_Goods]
GO
ALTER TABLE [dbo].[StorageInfo]  WITH CHECK ADD  CONSTRAINT [FK_StorageInfo_Depot] FOREIGN KEY([DepotId])
REFERENCES [dbo].[Depot] ([Id])
GO
ALTER TABLE [dbo].[StorageInfo] CHECK CONSTRAINT [FK_StorageInfo_Depot]
GO
ALTER TABLE [dbo].[StorageInfo]  WITH CHECK ADD  CONSTRAINT [FK_StorageInfo_Goods] FOREIGN KEY([GoodsId])
REFERENCES [dbo].[Goods] ([Id])
GO
ALTER TABLE [dbo].[StorageInfo] CHECK CONSTRAINT [FK_StorageInfo_Goods]
GO
USE [master]
GO
ALTER DATABASE [Storage] SET  READ_WRITE 
GO
